package com.hsgene.dict.config;

import com.hsgene.common.util.web.access.HttpDebugFilter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 过滤器配置
 *
 * @author wangbing
 * @version 1.0, 2018/7/6
 */
@Configuration
public class FilterConfig {

    @Value("${logback.http.debug}")
    private boolean logbackHttpDebug;

    @Bean
    public FilterRegistrationBean registerFilter() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(getAccessAuthorityFilter());
        registration.addUrlPatterns("/*");
        registration.addInitParameter("paramName", "paramValue");
        registration.setName("httpDebugFilter");
        return registration;
    }

    @Bean("httpDebugFilter")
    public HttpDebugFilter getAccessAuthorityFilter() {
        HttpDebugFilter httpDebugFilter = new HttpDebugFilter();
        httpDebugFilter.setLogbackHttpDebug(logbackHttpDebug);
        return httpDebugFilter;
    }
}
